﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RpgLibrary.CharacterClasses;

namespace RpgLibrary.SpellClasses
{
    public class Spell
    {
        #region Field Region
        
        string name;
        List<string> allowedClasses;
        Dictionary<string, int> attributeRequirements;
        List<string> spellPrerequisites;
        int levelRequirement;
        SpellType spellType;
        int activationCost;
        List<string> effects;
        
        #endregion
        
        #region Property Region
        
        public string Name
        {
            get { return name; }
        }
        
        public List<string> AllowedClasses
        {
            get { return allowedClasses; }
        }
        
        public Dictionary<string, int> AttributeRequirements
        {
            get { return attributeRequirements; }
        }
        
        public List<string> SpellPrerequisites
        {
            get { return spellPrerequisites; }
        }
        
        public int LevelRequirement
        {
            get { return levelRequirement; }
        }
        
        public SpellType SpellType
        {
            get { return spellType; }
        }
        
        public int ActivationCost
        {
            get { return activationCost; }
        }
        
        public List<string> Effects
        {
            get { return effects; }
        }
        
        #endregion
        
        #region Constructor Region
        
        private Spell()
        {
            allowedClasses = new List<string>();
            attributeRequirements = new Dictionary<string, int>();
            spellPrerequisites = new List<string>();
            effects = new List<string>();
        }
        
        #endregion
        
        #region Method Region
        
        public static Spell FromSpellData(SpellData data)
        {
            Spell spell = new Spell();
            
            spell.name = data.Name;
            
            foreach (string s in data.AllowedClasses)
                spell.allowedClasses.Add(s.ToLower());
            
            foreach (string s in data.AttributeRequirements.Keys)
                spell.attributeRequirements.Add(
                s.ToLower(),
                data.AttributeRequirements[s]);
            
            foreach (string s in data.SpellPrerequisites)
                spell.SpellPrerequisites.Add(s);
            
            spell.levelRequirement = data.LevelRequirement;
            spell.spellType = data.SpellType;
            spell.activationCost = data.ActivationCost;
            
            foreach (string s in data.Effects)
                spell.Effects.Add(s);
            
            return spell;
        }
        
        #endregion
        
        #region Virtual Method Region
        #endregion
    }
}